<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/10/26
 * Time: 22:39
 */
header('content-type:text/html;charset=utf-8');
require './public_function.php';
//dbInit();  
$link = mysqli_connect('localhost','root','','itcast');
if(!$link) {
    die('链接数据库失败' . mysqli_error($link));
}
mysqli_query($link,'set names utf8');

if(!empty($_POST)){
    $fields = array('e_name','e_dept','date_of_birth','date_of_entry');
    $value = array();
    foreach ($fields as $k =>$v){
        $data = isset($_POST[$v])? $_POST[$v] : '';
        if($data=='') die($v .'字段不能为空');
        $fields[$k] = "`$v`";
        $values[] = "'$data'";
    }
    $fields = implode(',', $fields);
    $values = implode(',', $values);
    $sql = "insert into `emp_info` ($fields) VALUES ($values)";
    if($res = mysqli_query($link,$sql)) {
        header('Location: ./showList.php');
        die;
    }else{
        die('员工添加失败！');
    }
}
define('APP','itcase');
require './add_html.php';